package com.jianz.campus_markets.controller;

import com.jianz.campus_markets.domain.ResponseResult;
import com.jianz.campus_markets.domain.entity.Product;
import com.jianz.campus_markets.service.AdminService;
import com.jianz.campus_markets.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author Jianz
 * @version 1.0
 * @Description
 * @Email jianz8153.gmail.com
 * @Date 2023/11/23 21:02
 */

@RestController
@RequestMapping("/admin")
@Api(value = "管理员模块")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @GetMapping("/getAllProducts")
    @ApiOperation(value = "管理员获取全部商品")
    @PreAuthorize("@ps.hasPermission('admin:getAllProducts')")   //权限控制，ps是PermissionService类的bean名称
    public ResponseResult getAllProducts(){
        return adminService.getAllProducts();
    }

    @PutMapping("/pass")
    @ApiOperation(value = "管理员审核通过")
    @PreAuthorize("@ps.hasPermission('admin:pass')")
    public ResponseResult passProduct(int productId){
        return adminService.passProduct(productId);
    }

    @PutMapping("/fail")
    @ApiOperation(value = "管理员审核未通过")
    @PreAuthorize("@ps.hasPermission('admin:fail')")
    public ResponseResult failProduct(int productId){
        return adminService.failProduct(productId);
    }

    @DeleteMapping("/off")
    @ApiOperation(value = "管理员下架商品")
    @PreAuthorize("@ps.hasPermission('admin:off')")
    public ResponseResult offProduct(int productId){
        return adminService.offProduct(productId);
    }
}
